﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Model.Bill;
using POS.Framework;
using BLL;

namespace POS.ModForm.Sale
{
    public partial class frmPayMent : DevExpress.XtraEditors.XtraForm
    {
        OrderBLL orderBLL = new OrderBLL();
        TB_Order order;
        public frmPayMent(TB_Order _order)
        {
            InitializeComponent();
            order = _order;
            groupControl1.Text = string.Format("销售单号：{0}", order.BillCode);
            this._lblCopeAmount.Text = order.CopeAmount.ToString("f2") + "￥";
            this._lblActualAmount.ToolTip = order.LowestAmount.ToString("f2") + "￥";
        }
        private void _ActualAmount_TextChanged(object sender, EventArgs e)
        {
            this._lblActualAmount.Text = this._ActualAmount.Text;
        }
        private void _ActualAmount_Click(object sender, EventArgs e)
        {
            this._lblActualAmount.SelectAll();
        }
        private void btnPayment_Click(object sender, EventArgs e)
        {
            decimal actualAmount = Convert.ToDecimal(this._ActualAmount.Text.Trim());
            if (string.IsNullOrEmpty(this._ActualAmount.Text.Trim()))
            {
                MsgBox.ShowWarning("请输入要付款的金额！");
                return;
            }
            if (actualAmount < order.LowestAmount)
            {
                MsgBox.ShowWarning("支付的金额低于销售单的最低销售金额！");
                return;
            }
            order.ActualAmount = actualAmount;
            string msg = orderBLL.Payment(order);
            if (string.IsNullOrEmpty(msg))
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            else
            {
                MsgBox.ShowWarning(msg);
            }
        }
    }
}